package part1.api.exception;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 异常处理机制在IO操作中运用
 */
public class FinallyDemo2 {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("./a/b/fos.dat");
        } catch (FileNotFoundException e) {
            System.out.println("出现了IO异常并解决了");

        }finally {
            try {
                fos.close();
            } catch (Exception e) {
                System.out.println("关闭流失出现异常并解决了");
                e.printStackTrace(); //打印出错信息，放在最后打印
            }
        }
        System.out.println("程序结束了");
    }
}
